package com.rrd.dw.mr.gzip.kafka;

import com.ucredit.babel.common.model.BaseModel;
import com.ucredit.babel.common.model.RecordType;
import com.ucredit.babel.common.model.third.phonehelp.MobileCreditA03Score;
import com.ucredit.babel.common.model.third.phonehelp.MobileCreditScoreA03Data;
import com.ucredit.babel.common.model.third.phonehelp.MobileCreditScoreA03Record;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper.Context;

import java.io.IOException;

/**
 * 电话邦邦信分
 *
 * @author xj
 */

public class PhonehelpCreditScoreRecordParse extends ParseBase {
    private Text val = new Text();
    private Text key = new Text();

    /**
     * 百融-履约风险识别
     *
     * @param model
     * @throws IOException
     * @throws InterruptedException
     */
    @Override
    public boolean parseJob(Context context, BaseModel<?> model, String successful) throws IOException, InterruptedException {
        MobileCreditScoreA03Record obj = (MobileCreditScoreA03Record) model;
        MobileCreditScoreA03Data data = obj.getData();
        if (data == null) {
            return false;
        }
        MobileCreditA03Score info = data.getData();

        StringBuilder sb = getBaseInfo(obj, successful);

        // 接口状态码
        sb.append(data.getStatus() == null ? "" : data.getStatus()).append(CRT001);
        // 主接口描述
        sb.append(data.getMsg() == null ? "" : data.getMsg()).append(CRT001);
        // 本次请求的唯一标识
        sb.append(info == null || info.getSid() == null ? "" :info.getSid()).append(CRT001);
        // 本次输出结果对应的有效日期
        sb.append(info == null || info.getResultDate() == null ? "" :info.getResultDate()).append(CRT001);
        // 号码所属的运营商代号
        sb.append(info == null || info.getCarrier() == null ? "" :info.getCarrier()).append(CRT001);
        // 邦信分评分_A03
        sb.append(info == null || info.getScore() == null ? "" :info.getScore()).append(CRT001);

        key.set(getKey());
        val.set(sb.toString().replace("\n", " ").replace("\r", " "));
        context.write(key, val);
        return true;
    }

    @Override
    public String getTableName() {
        return "kafka_babel_phonehelp_credit_score_record_inc";
    }

    @Override
    public String getType() {
        return RecordType.MOBILE_CREDITSCORE_A03_RECORD.toString();
    }

    @Override
    public String getComment() {
        return "电话邦邦信分";
    }
}
